const Joi = require('joi');

/* register */
exports.register = function(value) {
  const schema = Joi.object({
    name: Joi.string().min(1).required(),
    maddr: Joi.string().email().required(),
    pwd: Joi.string().min(6).required()

  }).unknown(true);
  const { error } = schema.validate(value);
  return error;
}

/* verify_auth */
exports.verfiy = function(value) {
  const schema = Joi.object({
    maddr: Joi.string().email().required(),
    code: Joi.string().required(),
    pwd: Joi.string().min(6)
  }).unknown(true);
  const { error } = schema.validate(value);
  return error;
}

/* sendEmailCode */
exports.sendEmailCode = function(value) {
  const schema = Joi.object({
    maddr: Joi.string().email().required()
  }).unknown(true);
  const { error } = schema.validate(value);
  return error;
}

/* login */
exports.login = function(value) {
  const schema = Joi.object({
    maddr: Joi.string().email().required(),
    pwd: Joi.string().min(6).required(),
    platform: Joi.number().integer().required(),
    deviceName: Joi.string().allow(''),
    deviceNo:Joi.string().required()
  }).unknown(true);
  const { error } = schema.validate(value);
  return error;
}

/* create building */
exports.building = function(value) {
  const schema = Joi.object({
    maddr: Joi.string().email().required(),
    token: Joi.string().required(),
    buildingUUID: Joi.string().required(),
    deviceNo:Joi.string().required(),
    buildingName:Joi.string().allow(''),
    companyName:Joi.string().allow(''),
    address:Joi.string().allow(''),
    city:Joi.string().allow(''),
    introduction:Joi.string().allow(''),
    isSelected:Joi.number().integer().max(1)
  }).unknown(true);
  const { error } = schema.validate(value);
  return error;
}

/* create mesh */
exports.createMesh = function(value) {
  const schema = Joi.object({
    maddr: Joi.string().email().required(),
    token: Joi.string().required(),
    meshUUID: Joi.string().required(),
    buildingUUID: Joi.string().required(),
    deviceNo:Joi.string().required(),
    meshName:Joi.string().required()
  }).unknown(true);
  const { error } = schema.validate(value);
  return error;
}

/* fileUpload imageUpload version*/
exports.fileUpload = function(value) {
  const schema = Joi.object({
    maddr: Joi.string().email().required(),
    token: Joi.string().required(),
    meshUUID: Joi.string().required(),
    deviceNo:Joi.string().required(),
    version:Joi.number().integer().required()
  }).unknown(true);
  const { error } = schema.validate(value);
  return error;
}

/* create get_mesh_info delete_building_mesh*/
exports.getBuilding = function(value) {
  const schema = Joi.object({
    maddr: Joi.string().email().required(),
    token: Joi.string().required(),
    deviceNo:Joi.string().required()
  }).unknown(true);
  const { error } = schema.validate(value);
  return error;
}

/* create share QR code */
exports.shareQRCode = function(value) {
  const schema = Joi.object({
    maddr: Joi.string().email().required(),
    deviceNo:Joi.string().required(),
    token: Joi.string().required(),
    buildingUUID: Joi.string().required(),
    role:Joi.number().integer().min(1).max(2)
  }).unknown(true);
  const { error } = schema.validate(value);
  return error;
}

/* create scan QR code */
exports.scanCode = function(value) {
  const schema = Joi.object({
    maddr: Joi.string().email().required(),
    deviceNo:Joi.string().required(),
    token: Joi.string().required(),
    QRCodeUUID: Joi.string().required()
  }).unknown(true);
  const { error } = schema.validate(value);
  return error;
}

/* version*/
exports.version = function(value) {
  const schema = Joi.object({
    maddr: Joi.string().email().required(),
    token: Joi.string().required(),
    deviceNo:Joi.string().required()
  }).unknown(true);
  const { error } = schema.validate(value);
  return error;
}

/* updateUserInfo*/
exports.updateUserInfo = function(value) {
  const schema = Joi.object({
    maddr: Joi.string().email().required(),
    token: Joi.string().required(),
    deviceNo:Joi.string().required(),
    name: Joi.string().required()
  }).unknown(true);
  const { error } = schema.validate(value);
  return error;
}

/* delete_user */
exports.deleteUser = function(value) {
  const schema = Joi.object({
    maddr: Joi.string().email().required(),
    token: Joi.string().required(),
    deviceNo:Joi.string().required()
  }).unknown(true);
  const { error } = schema.validate(value);
  return error;
}

/* mesh QR_receiver_list*/
exports.mesh = function(value) {
  const schema = Joi.object({
    maddr: Joi.string().email().required(),
    token: Joi.string().required(),
    deviceNo:Joi.string().required(),
    buildingUUID: Joi.string().required()
  }).unknown(true);
  const { error } = schema.validate(value);
  return error;
}

/* head version*/
exports.head = function(value) {
  const schema = Joi.object({
    maddr: Joi.string().email().required(),
    token: Joi.string().required(),
    deviceNo:Joi.string().required()
  }).unknown(true);
  const { error } = schema.validate(value);
  return error;
}

/* del_share_building*/
exports.delShareBuilding = function(value) {
  const schema = Joi.object({
    maddr: Joi.string().email().required(),
    token: Joi.string().required(),
    deviceNo:Joi.string().required(),
    buildingUUID: Joi.string().required(),
    receiver: Joi.string().required(),
  }).unknown(true);
  const { error } = schema.validate(value);
  return error;
}
